﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:OpenSearch.Controls"
                    xmlns:Util="clr-namespace:OpenSearch.Client.Util;assembly=OpenSearch.Client"
                    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
                    xmlns:Client="clr-namespace:OpenSearch.Client;assembly=OpenSearch.Client"
                    xmlns:c="clr-namespace:Wpf.Controls;assembly=Wpf.SplitButton">


  <Style TargetType="{x:Type local:SearchBox}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:SearchBox}">
          <ControlTemplate.Resources>
            <DataTemplate DataType="{x:Type Util:SearchSuggestion}">
              <StackPanel Orientation="Horizontal" Margin="0,2,0,2">
                <Image x:Name="img" Visibility="Collapsed" ToolTip="{Binding ImageAlt}"
                       Height="{Binding Height}" Width="{Binding Width}" Margin="0,0,5,0" />
                <TextBlock Text="{Binding Text}" VerticalAlignment="Center" />
              </StackPanel>
              <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding HasImage}" Value="True">
                  <Setter TargetName="img" Property="Visibility" Value="Visible" />
                  <Setter TargetName="img" Property="Source" Value="{Binding Image}" />
                </DataTrigger>
              </DataTemplate.Triggers>
            </DataTemplate>


          </ControlTemplate.Resources>

          <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}" Height="25" VerticalAlignment="Top">
            <DockPanel LastChildFill="True">

              <c:SplitButton IsTabStop="True" TabIndex="2" x:Name="PART_SearchButton" Mode="Split"
                             DockPanel.Dock="Right">
                <c:SplitButton.Content>
                  <Image Width="16" Height="16"
                         Source="{Binding CurrentClient.ImageLocation, RelativeSource={RelativeSource TemplatedParent}}"
                         ToolTip="{Binding CurrentClient.Name, RelativeSource={RelativeSource TemplatedParent}}" />
                </c:SplitButton.Content>
              </c:SplitButton>
              <Controls:AutoCompleteBox x:Name="PART_AutoCompleteBox"
                                        ItemsSource="{Binding CurrentClient.Suggestions, RelativeSource={RelativeSource TemplatedParent}}"
                                        MinimumPopulateDelay="250" />

            </DockPanel>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>